package com.yingyi.service.impl;

import com.yingyi.BusinessException;
import com.yingyi.feign.StoreFeignService;
import com.yingyi.mapper.ProductMapper;
import com.yingyi.service.IProductService;
import com.yingyi.domain.Product;
import com.yingyi.domain.Store;
import com.yingyi.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private StoreFeignService storeFeignService;

    @Override
    public void add(Product product) {
        productMapper.add(product);

        Store store = new Store();
        store.setProductId(product.getId());
        store.setNumber(product.getNumber());
        JsonResult result = storeFeignService.add(store);
        if (!result.getSuccess()) {
            throw new BusinessException("存储失败，稍后重试");
         }
    }
}
